package cn.onlineclass.keyun.web;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter("/*")
//全局处理异常！
public class RoleFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        try {
            chain.doFilter(req, resp);
        }catch (Exception e){
            e.printStackTrace();
            resp.setContentType("application/json;charset=utf-8");
            resp.getWriter().print("{\"code\":500,\"msg\":\""+e+"\"}");
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
